<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>外部订单添加</title>
	<meta name="decorator" content="default"/>
	
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/bu/buExternalOrder/">外部订单列表</a></li>
		<li class="active"><a href="${ctx}/bu/buExternalOrder/form?id=${buOrder.id}&flag=2">外部订单
		<c:choose>
		   <c:when test="${flag eq 0}">
		   		<shiro:hasPermission name="bu:buExternalOrder:operate:edit">${not empty buOrder.id?'修改':'添加'}</shiro:hasPermission></a>
		   </c:when>
		   <c:when test="${flag eq 2}">
		   		<shiro:hasPermission name="bu:buExternalOrder:operate:edit">查看</shiro:hasPermission></a>
		   </c:when>
		   <c:otherwise>
		   		<shiro:hasPermission name="bu:buExternalOrder:operate:copy">复制</shiro:hasPermission></a>
		   </c:otherwise>
		</c:choose>
		</li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="buOrder" action="${ctx}/bu/buExternalOrder/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<input type="hidden" name="flag" value="${flag}" />
		<input type="hidden" name="id" id="id" value="${id}" />
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">订单编号：</label>
			<div class="controls">
				<form:input path="orderNo" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">生产编号：</label>
			<div class="controls">
				<form:input path="productNo" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">客户订单编号：</label>
			<div class="controls">
				<form:input path="customerOrderNo" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">下单日期：</label>
			<div class="controls">
				<form:input path="orderDate" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">出货日期：</label>
			<div class="controls">
				<input name="shipDate" readonly="true" type="text" readonly="true" maxlength="20" class="input-medium Wdate "
					value="<fmt:formatDate value="${buOrder.shipDate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">产品名称：</label>
			<div class="controls">
				<form:input path="productName" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">工艺：</label>
			<div class="controls">
				<form:input path="crafts" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
				<label class="control-label">是否初订：</label>
				<div class="controls">
					<form:radiobuttons path="status" disabled="true" items="${fns:getDictList('order_status')}" itemLabel="label" itemValue="value" htmlEscape="false" class="required"/>
				</div>
			</div>
		<div class="control-group">
			<label class="control-label">抛光：</label>
			<div class="controls">
				<form:input path="polishing" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">电镀：</label>
			<div class="controls">
				<form:input path="electroplate" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">背面：</label>
			<div class="controls">
				<form:input path="back" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">包装：</label>
			<div class="controls">
				<form:input path="packages" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">配件：</label>
			<div class="controls">
				<form:input path="fitting" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">材质：</label>
			<div class="controls">
				<form:input path="material" readonly="true" onkeydown="changeFocus()" htmlEscape="false" maxlength="64" class="input-xlarge "/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">图片：</label>
			<div class="controls">
				    <input type="hidden" name="picUrl" id="picUrl">
					<img src="" alt="" id="avatarShow" class="picstyle">
					<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">尺寸：</label>
			<div class="controls">
				<form:input path="productSize" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">厚度：</label>
			<div class="controls">
				<form:input path="thinkness" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">快递单名称：</label>
			<div class="controls">
				<form:input path="deliveryName" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">快递单号：</label>
			<div class="controls">
				<form:input path="deliveryNumber" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">运费：</label>
			<div class="controls">
				<form:input path="freight" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">数量：</label>
			<div class="controls">
				<form:input path="quantity" readonly="true" htmlEscape="false" maxlength="11" class="input-xlarge " id="quantity"
				onkeyup="value=value.replace(/[^\d]/g,'')"/>
			</div>
		</div>
		<shiro:hasPermission name="bu:buExternalOrder:operate:salesPrice">
			<div class="control-group">
				<label class="control-label">销售单价：</label>
				<div class="controls">
					<form:input path="salesPrice" readonly="true" htmlEscape="false" class="input-xlarge" id="salesPrice"/>
				</div>
			</div>
		</shiro:hasPermission>
		<shiro:hasPermission name="bu:buExternalOrder:operate:salesModelFee">
		<div class="control-group">
			<label class="control-label">销售模费：</label>
			<div class="controls">
				<form:input path="salesModelFee" readonly="true" htmlEscape="false" class="input-xlarge " id="salesModelFee"/>
			</div>
		</div>
		</shiro:hasPermission>
		<div class="control-group">
			<label class="control-label">生产单价：</label>
			<div class="controls">
				<form:input path="produceFee" readonly="true" htmlEscape="false" class="input-xlarge " id="produceFee"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">生产模费：</label>
			<div class="controls">
				<form:input path="produceModelFee" readonly="true" htmlEscape="false" class="input-xlarge " id="produceModelFee"/>
			</div>
		</div>
		<shiro:hasPermission name="bu:buExternalOrder:operate:salesTotalFee">
			<div class="control-group">
				<label class="control-label">销售总价：</label>
				<div class="controls">
					<form:input path="salesTotalFee" readonly="true" htmlEscape="false" class="input-xlarge " id="salesTotalFee"/>
				</div>
			</div>
		</shiro:hasPermission>
		<div class="control-group">
			<label class="control-label">生产总价：</label>
			<div class="controls">
				<form:input path="produceTotalFee" readonly="true" htmlEscape="false" class="input-xlarge " id="produceTotalFee"/>
			</div>
		</div>
		<shiro:hasPermission name="bu:buExternalOrder:operate:profit">
			<div class="control-group">
				<label class="control-label">利润：</label>
				<div class="controls">
					<form:input path="profit" readonly="true" htmlEscape="false" class="input-xlarge " id="produceTotalFee"/>
				</div>
			</div>
		</shiro:hasPermission>
		<div class="control-group">
			<label class="control-label">业务员名称：</label>
			<div class="controls">
				<form:select path="customerId" id="customerId" name="customerId" class="input-xlarge ">
					<form:option value="" label="--请选择业务员--"/>
					<form:options items="${customerList}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<shiro:hasPermission name="bu:buExternalOrder:operate:salesmanName">
		<div class="control-group">
			<label class="control-label">客户名称：</label>
			<div class="controls">
				<form:select id="salesmanId" name="salesmanId" path="salesmanId" class="input-xlarge ">
					<form:options items="${entityList}" itemLabel="salesmanName" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		</shiro:hasPermission>
		<div class="control-group">
			<label class="control-label">供应商名称：</label>
			<div class="controls">
				<form:select path="supplierId" id="supplierId" name="supplierId" readonly="true" class="input-xlarge ">
					<form:option value="" label="--请选择供应商--"/>
					<form:options items="${supplierList}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">创建人：</label>
			<div class="controls">
				<form:input path="createUser" readonly="true" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:textarea path="remarks" readonly="true" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
	<script type="text/javascript">
		$(document).ready(function(){
				var picUrl = '${buOrder.picUrl}';
				var picPrefix = '${picPrefix}';
				$("#picUrl").attr("value",picUrl);
				$("#avatarShow").attr("src",picPrefix + picUrl);	
		});
	</script>
	<script type="text/javascript">
	
		 function changSalesMan(v,w){
			   console.log(v);
				    $.ajax({
				        type : "post",
				        async : false,
				        url : "${ctx}/bu/buExternalOrder/selectButtonSalesList",
				        data : {
				            'id': v,
				            'orderId': w
				        },
				        dataType : "json",
				        success : function(msg) {
				            $("#salesmanId").empty();
				            console.log(msg.salesmanId.length);
				            if (msg.salesmanId.length > 0) {
				                for (var i = 0; i < msg.salesmanId.length; i++) {
				                        var partId = msg.salesmanId[i].id;
				                        var partName = msg.salesmanId[i].salesmanName;
				                        var $option = $("<option>").attr({
				                            "value" : partId
				                        }).text(partName);
				                        $("#salesmanId").append($option);
				                }
				        }else{
				        	$("#salesmanId").empty();
				        }
				    }, error : function(json) {
			            $.jBox.alert("网络异常！");
			        }
				    })
		   }
	
		$(document).ready(function() {
			$("#salesmanId").prop("disabled", true);
			$("#supplierId").prop("disabled", true);
			$("#customerId").prop("disabled", true);
			var orderId = $("#id").val();
			console.log("~~~~~~~~~~~~~~~~~~~",$("#id").val());
			var customerId = $("#customerId").find("option:selected").val();
			changSalesMan(customerId,orderId);
			
			$("#inputForm").validate({
				submitHandler: function(form){
					$("#salesmanId").prop("disabled", false);
					$("#supplierId").prop("disabled", false);
					$("#customerId").prop("disabled",false);
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
	<style>
		.picstyle {width:auto;max-width:1200px;height: auto;}
	</style>
</body>
</html>